﻿<!DOCTYPE html>
<html lang="en">
<head>
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=1">
    <meta name="format-detection" content="telephone=no">
    <meta charset="UTF-8">
    <title>watch&localStorage</title>
    <link rel="stylesheet" href="../css/bootstrap.css"/>
    <script src="../js/jquery-2.2.0.min.js"></script>
    <script src="../js/bootstrap.min.js"></script>
</head>
<body>
<h1>watch&localStorage</h1><br/>

<div id="app">
    {{name}}<br/>
    <input type="text" v-model="todo.txt"/><br/>
    <input type="text" v-model="shendu.txt"/>
</div>
<script src="../js/vue-2.5.16.js"></script>
<script src="../node_modules/axios/dist/axios.js"></script>
<script src="../node_modules/lodash/lodash.js"></script>

<script>
    var app = new Vue({
        el:'#app',
        data:{
            name:'模版数据',
            todo:{
                txt:''
            },
            shendu:{
                txt:''
            }
        },
        watch:{
            todo(){
                console.log(1);//直接监控todo该对象，不起作用的原因是引用的地址并没有变，只是里面某个属性值变了不会监控到，想也监控到使用深度监控,或者该对象或者数组加了属性或者数组里添加了新的项
            },
            shendu:{
                handler(newValue,oldValue){//默认写成函数，就是默认写了handler
                    console.log(newValue);
                    console.log(oldValue);
                    //localStorage.setItem('data',JSON.stringify(shendu));
                },
                deep:true
            }
        }
    });
</script>

</body>
</html>